import { checkByName, checkByCode } from '@/api/admin/tenant'

let validateName = (rule, value, callback) => {
  if (window.boxType === 'edit') {
    callback()
    return;
  }
  checkByName(value)
    .then(resp => {
      if (resp.data.data > 0) {
        callback(new Error('租户名称已存在'))
      } else {
        callback()
      }
    })
}
let validateCode = (rule, value, callback) => {
  if (window.boxType === 'edit') {
    callback()
    return;
  }
  checkByCode(value)
    .then(resp => {
      if (resp.data.data > 0) {
        callback(new Error('租户编码已存在'))
      } else {
        callback()
      }
    })
}
export const tableOption = {
  border: true,
  index: true,
  indexLabel: '序号',
  stripe: true,
  menuAlign: 'center',
  searchMenuSpan: 6,
  align: 'center',
  column: [
    {
      label: '租户ID',
      prop: 'id',
      hide: true,
      editDisabled: true,
      editDisplay: false,
      addDisplay: false
    },
    {
      label: '租户名称',
      prop: 'name',
      search: true,
      rules: [
        { required: true, message: '请输入租户名称', trigger: 'blur'},
        { min: 2, max: 32, message: '长度在 2 到 32 个字符', trigger: 'blur'},
        { validator: validateName, trigger: 'blur'}
      ]
    },
    {
      label: '租户标识',
      prop: 'code',
      search: true,
      rules: [
        { required: true,message: '请输入租户编号',trigger: 'blur'},
        { validator: validateCode, trigger: 'blur'}
      ]
    },
    {
      label: '开始时间',
      prop: 'startTime',
      type: 'datetime',
      format: 'yyyy-MM-dd hh:mm:ss',
      valueFormat: 'yyyy-MM-dd hh:mm:ss',
      rules: [{
        required: true,
        message: '请输入结束时间',
        trigger: 'blur'
      }]
    },
    {
      label: '结束时间',
      prop: 'endTime',
      type: 'datetime',
      format: 'yyyy-MM-dd hh:mm:ss',
      valueFormat: 'yyyy-MM-dd hh:mm:ss',
      rules: [{
        required: true,
        message: '请输入结束时间',
        trigger: 'blur'
      }]
    },
    // {
    //   label: '状态',
    //   prop: 'status',
    //   type: 'radio',
    //   border:true,
    //   dicUrl: '/admin/dict/type/status_type',
    //   search: true
    // }
    {
      label: '数据源',
      prop: 'datasource',
      type: 'select',
      dicUrl: '/admin/gen/dsconf/select',
      rules: [{
        required: true,
        message: '请选择数据源',
        trigger: 'blur'
      }]
    }
  ]
}
